package org.example.hotel.controller;

import org.example.hotel.dto.LoginRequest;
import org.example.hotel.dto.RoomLoginRequest;
import org.example.hotel.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/room")
    public ResponseEntity<?> loginRoom(@RequestBody RoomLoginRequest request) {
        boolean success = loginService.validateRoomLogin(request.getRoomNumber(), request.getCardPassword());
        return success ? ResponseEntity.ok("房客登录成功") : ResponseEntity.status(401).body("房间号或密码错误");
    }

    @PostMapping("/system")
    public ResponseEntity<?> loginSystem(@RequestBody LoginRequest request) {
        boolean success = loginService.validateSystemLogin(request.getRole(), request.getPassword());
        return success ? ResponseEntity.ok("系统用户登录成功") : ResponseEntity.status(401).body("密码错误");
    }
}
